package 力扣日常刷题.木22二月.第07天213;

import 力扣日常刷题.TreeNode;

/**
 * @author 帅小伙
 * @date 2022/2/13
 * @description
 */
public class Demo53JZ平衡二叉树 {


    public boolean isBalanced(TreeNode root) {
        if (root == null) return true;
        return isBalanced(root.left) && isBalanced(root.right) &&
                (Math.abs(depth(root.left) - depth(root.right)) <= 1);
    }

    public int depth(TreeNode node){
        if (node == null) return 0;
        else return Math.max(depth(node.left),depth(node.right)) + 1;
    }
}
